Data comes from
---
title: "Key U.S. Economic Indicators"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
source_code: embed
---
<!-- add "next data release date" for each!-->
<!-- Organize by category...employment, prices, growth -->
<!--
- make main page a series of valueboxes, linked to individual pages
- macro indicators
- gdp/growth/capita
- US federal budget deficit
- US federal debt, debt/gdp
- unemployment
- labor force participation
- tfp, labor productivity, labor share?
- inflation
- cpi
- core cpi
- forecasted inflation
- prices
- interest rates
- yield curve
- treasury yields
- treasury spread
- rents
- commodities: gasoline, oil,
- TIPS
## Asset Prices
- stocks (S&P 500, Vanguard)
- home prices
- rental prices
-
-->
```{r setup, include=FALSE}
library(here)
library(tidyverse)
here::i_am("econ_dash.Rmd")
path <- here::here("R") # scripts source
source_files <- list.files(path, "*.R$") # locate all .R files
map(paste0(path, "/", source_files), source) # source all .R scripts
```
```{r}
# Fed Funds Rate
ffr_latest <- paste0(get_latest_value(ffr),"%")
ffr_latest_date <- get_latest_date(ffr)
# Gas Price
gas_latest <- paste0("$", round(get_latest_value(gas), 2), "/gallon")
gas_latest_date <- get_latest_date(gas)
# Oil Price
oil_latest <- paste0("$", round(get_latest_value(oil), 2), "/barrel")
oil_latest_date <- get_latest_date(oil)
# Fed Funds Rate
cpi_latest <- paste0(round(get_latest_value(cpi),2),"%")
cpi_latest_date <- get_latest_date(cpi)
# Mortgage Rate
mortgage_latest <- paste0(round(get_latest_value(mortgage),2),"%")
mortgage_latest_date <- get_latest_date(mortgage)
# GDP
gdp_latest <- paste0("$",round(0.001*get_latest_value(gdp),3), " Trillion")
gdp_latest_date <- get_latest_date(gdp)
# Real GDP
rgdp_latest <- paste0("$",round(get_latest_value(rgdp),0))
rgdp_latest_date <- get_latest_date(rgdp)
# Real GDP per Capita
rgdp_pc_latest <- paste0("$",round(get_latest_value(rgdp_pc),0))
rgdp_pc_latest_date <- get_latest_date(rgdp_pc)
# Real GDP Growth Rate
rgdp_growth_latest <- paste0(round(get_latest_value(rgdp_growth),2),"%")
rgdp_growth_latest_date <- get_latest_date(rgdp_growth)
# Unemployment Rate
ur_latest <- paste0(round(get_latest_value(ur),2),"%")
ur_latest_date <- get_latest_date(ur)
# Labor Force Participation Rate
lfpr_latest <- paste0(round(get_latest_value(lfpr),2),"%")
lfpr_latest_date <- get_latest_date(lfpr)
```
```{r, eval=F}
ffr_current <- ffr %>%
arrange(desc(date)) %>%
slice(1) %>%
pull(value) %>%
paste0(., "%")
ffr_current_date <- ffr %>%
arrange(desc(date)) %>%
slice(1) %>%
pull(date)
```
Indicators at a Glance
===============
Macroeconomic Conditions {data-width=650}
-------------------------
### Gross Domestic Product (as of `r gdp_latest_date`) {.value-box}
```{r}
valueBox(value = gdp_latest, icon = "fa-tag")
```
### Unemployment Rate (as of `r ur_latest_date`) {.value-box}
```{r}
valueBox(value = ur_latest, icon = "fa-briefcase")
```
### Consumer Price Index — Percent Change from 1 Year Ago (as of `r cpi_latest_date`) {.value-box}
```{r}
valueBox(value = cpi_latest, icon = "fa-solid fa-money-bill-trend-up")
```
### Yield Curve
```{r}
valueBox(value = yc_status, icon = "fa-chart-line",
color = ifelse(yc_status == "Normal", "green", "orange"))
```
Asset Prices {data-width=650}
--------------------------
### Federal Funds Rate (as of `r ffr_latest_date`) {.value-box}
```{r}
valueBox(value = ffr_latest, icon = "fa-percent")
```
### Gas Price (as of `r gas_latest_date`) {.value-box}
```{r}
valueBox(value = gas_latest, icon = "fa-gas-pump")
```
### Oil Price (as of `r oil_latest_date`) {.value-box}
```{r}
valueBox(value = oil_latest, icon = "oil-well")
```
### Average 30-Year Fixed Mortgage Rate (as of `r mortgage_latest_date`) {.value-box}
```{r}
valueBox(value = mortgage_latest, icon = "house")
```
Key Prices
=======================================================================
Column {data-width=650}
-----------------------------------------------------------------------
### Federal Funds Rate
```{r}
plot_ffr <-ggplot(data = ffr)+
aes(x = date,
y = value,
color = series_id)+
geom_rect(data = recs,
aes(xmin = start, xmax = end, ymin = -Inf, ymax = Inf),
inherit.aes = FALSE, fill = "black", alpha = 0.3)+
geom_path(size=1)+
geom_hline(yintercept=0, size=1)+
scale_x_date(limits=as.Date(c("1955-01-01", "2022-07-01")),
date_breaks = "5 years",
#minor_breaks = "2 years",
date_labels = "%Y",
expand = c(0,0))+
scale_y_continuous(breaks=seq(0,20,2),
labels=function(x){paste0(x,"%")},
limits = c(0,20),
expand = c(0,0))+
labs(x = "Year",
y = "Federal Funds Rate",
caption = "Data Source: FRED; Recessions Shaded in Gray")+
theme_classic(base_family = "Fira Sans Condensed", base_size = 16)+
theme(legend.position="none")
plot_ffr # %>% plotly::ggplotly()
```
Column {data-width=350}
-----------------------------------------------------------------------
### Chart B
```{r}
library(xts)
ffr %>%
select(value) %>%
rename("Fed Funds Rate" = value) %>%
xts(., order.by = as.Date(ffr$date)) %>%
dygraph() %>%
dyRangeSelector()
```
### Chart C
```{r}
library(highcharter)
hchart(ffr, "line", hcaes(x = date, y = value))
```
Interest Rates
===============
Column {data-width=650}
-----------------------------------------------------------------------
```{r}
dy_graph(ffr, "Federal Funds Rate", "percent", shade_recessions = TRUE)
```
Column {data-width=650}
-----------------------------------------------------------------------
```{r}
yield_curve
```
Gasoline
===============
Column {data-width=650}
-----------------------------------------------------------------------
### Gasoline
```{r}
plot_gas <-ggplot(data = gas)+
aes(x = date,
y = value,
color = series_id)+
geom_rect(data = recs,
aes(xmin = start, xmax = end, ymin = -Inf, ymax = Inf),
inherit.aes = FALSE, fill = "black", alpha = 0.3)+
geom_path(size=1)+
geom_hline(yintercept=0, size=1)+
scale_x_date(limits=as.Date(c("1990-01-01", gas_latest_date)),
date_breaks = "2 years",
minor_breaks = "2 years",
date_labels = "%Y",
expand = c(0,0))+
scale_y_continuous(breaks=seq(0,5.25,0.25),
labels=scales::dollar_format(),
limits = c(0,5.25),
expand = c(0,0))+
labs(x = "Year",
y = "Price/gal",
subtitle = "US Regular All Formulations Gas Price",
caption = "Data Source: FRED; Recessions Shaded in Gray")+
ggthemes::theme_pander(base_family = "Fira Sans Condensed", base_size = 16)+
theme(legend.position="none")
plot_gas #%>% plotly::ggplotly()
```
Column {data-width=650}
-----------------
### Oil
```{r}
plot_oil <- ggplot(data = oil)+
aes(x = date,
y = value,
color = series_id)+
geom_rect(data = recs,
aes(xmin = start, xmax = end, ymin = -Inf, ymax = Inf),
inherit.aes = FALSE, fill = "black", alpha = 0.3)+
geom_path(size=1)+
geom_hline(yintercept=0, size=1)+
scale_x_date(limits=as.Date(c("1950-01-01", oil_latest_date)),
date_breaks = "5 years",
minor_breaks = "2 years",
date_labels = "%Y",
expand = c(0,0))+
scale_y_continuous(breaks=seq(0,150,20),
labels=scales::dollar_format(),
limits = c(0,150),
expand = c(0,0))+
labs(x = "Year",
y = "Price/barrel",
subtitle = "Crude Oil Prices: West Texas Intermediate (WTI) - Cushing, Oklahoma",
caption = "Data Source: FRED; Recessions Shaded in Gray")+
ggthemes::theme_pander(base_family = "Fira Sans Condensed", base_size = 16)+
theme(legend.position="none")
plot_oil #%>% plotly::ggplotly()
```
Labor Markets
============================
Column {data-width=650}
-----------------
### Unemployment Rate (as of `r ur_latest_date`) {.value-box}
```{r}
valueBox(value = ur_latest, icon = "fa-briefcase")
```
### Unemployment Rate
```{r}
dy_graph(ur, "Unemployment Rate", "percent", line_color = "red", shade_recessions = TRUE)
```
Column {data-width=650}
-----------------
### Labor Force Participation Rate
```{r}
dy_graph(lfpr, "Labor Force Participation Rate", "percent", line_color = "darkgreen", shade_recessions = TRUE)
```
### Labor Force Participation Rate - Men
```{r}
dy_graph(lfpr_m, "Labor Force Participation Rate", "percent", line_color = "lightblue", shade_recessions = TRUE)
```
### Labor Force Participation Rate - Women
```{r}
dy_graph(lfpr_f, "Labor Force Participation Rate", "percent", line_color = "pink", shade_recessions = TRUE)
```
Data Sources
============================
Data comes from
- Bureau of Economic Analysis
- Gross Domestic Product
- Bureau of Labor Statistics